Skip to content

Conversation

@mnishiguchi
Copy link
Contributor

@mnishiguchi mnishiguchi commented Jan 26, 2026

I tested it with my ESP32-S3 + v0.6.6 image.

Here is example log output:

AtomVM init.
I (609) sys: Loaded BEAM partition main.avm at address 0x250000 (size=1048576 bytes)
Starting application...
Loading count from NVS ...
Loaded count: 313
This device has restarted 314 time(s).
Saving count to NVS ...
Restarting in 10 seconds ...

@petermm
Copy link
Collaborator

petermm commented Jan 26, 2026

Thank you!

I'm not sure we want to show writing this much to nvs - see the warning here: https://doc.atomvm.org/latest/programmers-guide.html#non-volatile-storage

Maybe change it to RTC https://doc.atomvm.org/latest/programmers-guide.html#rtc-memory - which obviously doesn't survive power outs, but doesn't wear down the flash..

@mnishiguchi
Copy link
Contributor Author

Oh that makes sense — frequent writes to NVS are a bad pattern. I can convert the counter to RTC and revise the NVS usage to something that doesn’t write often, resulting in two examples.

@petermm
Copy link
Collaborator

petermm commented Jan 26, 2026

yeah, remember to try/catch the rtc_slow_get_binary() - as it will raise badarg when not set eg for you on first boot..

@mnishiguchi mnishiguchi force-pushed the feat/add-elixir-esp-nvs-example branch from b50f818 to 12d5ef2 Compare January 26, 2026 13:42
@mnishiguchi
Copy link
Contributor Author

Thanks for the feedback.

I updated the examples to avoid frequent NVS writes:

  • EspNvs now writes the default value only once (when the key is missing) and then just logs the fetch result before restarting.
  • The restart counter example was moved to EspRtc using RTC slow memory (so it survives software resets without wearing flash).

Example output:

EspNvs:

Fetched word from NVS: AtomVM
Restarting in 10 seconds ...

EspRtc:

Loading count from RTC slow memory ...
This device has restarted 2 time(s).
Saving count to RTC slow memory ...
Restarting in 10 seconds ...

@UncleGrumpy
Copy link
Collaborator

I'm not sure we want to show writing this much to nvs - see the warning here: https:

Excellent point! I should have caught this.

@mnishiguchi mnishiguchi force-pushed the feat/add-elixir-esp-nvs-example branch from 12d5ef2 to 3ce9e58 Compare January 27, 2026 00:17
@mnishiguchi
Copy link
Contributor Author

mnishiguchi commented Jan 27, 2026

We could also add standardized .gitignore and .formatter.exs files across all Elixir examples for consistency.

Potentially .tool-versions as well.

@mnishiguchi
Copy link
Contributor Author

I'm wondering what the ideal name for the RTC slow memory example would be. Should we use something more specific, like EspRtcSlowMemory?

@UncleGrumpy
Copy link
Collaborator

I'm wondering what the ideal name for the RTC slow memory example would be. Should we use something more specific, like EspRtcSlowMemory?

I think EspRtcMemory is good.

@UncleGrumpy
Copy link
Collaborator

UncleGrumpy commented Jan 27, 2026

We could also add standardized .gitignore and .formatter.exs files across all Elixir examples for consistency.

Potentially .tool-versions as well.

I would not add .tool-versions, this should be up to the users choice.

.gitignore is fine, but for simplicity I would prefer just one set of rules in the root directory, it can get harder to keep track of individual files through the directory tree.

I am not sure if we need a formatter.exs, we just want to follow default formatting rules. But I am much more familiar with Erlang and erlfmt, which is what we use for all AtomVM org repos.

@petermm
Copy link
Collaborator

petermm commented Jan 27, 2026

Agree, I suggest not handling the projectwide .gitignore here though - also something good about seeing the avm file in git diff etc. so maybe no .gitignore is needed..

@mnishiguchi mnishiguchi force-pushed the feat/add-elixir-esp-nvs-example branch from 3ce9e58 to c8a1ad9 Compare January 27, 2026 11:27
@petermm
Copy link
Collaborator

petermm commented Jan 27, 2026

this is great!

I will have to admit I'm backtracking on the %__MODULE__{} once I see it - while it's obvious to us, for a beginner it looks very advanced and implicit..

Should we have RebootState.ex in a separate file? then we also show good separation of everything.. and it's obvious to a beginner..

Sorry about not thinking the feedback through!

@mnishiguchi mnishiguchi force-pushed the feat/add-elixir-esp-nvs-example branch from c8a1ad9 to 8449b93 Compare January 27, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants